{##
 # TODO: description
 #
 # @copyright  Copyright (c) 2010-2011 The Fajr authors (see AUTHORS).
 #             Use of this source code is governed by a MIT license that can be
 #             found in the LICENSE file in the project root directory.
 # @author     TODO
 #}
{% extends "layout/studium.xhtml" %}
{% block title %}Prihlásenie na skúšky{% endblock %}
{% block application_content %}
{% import "macros/decorators.xhtml" as decorators %}
{% import "macros/table.xhtml" as table %}
{% import "macros/studium.xhtml" as studiumMacros %}
{{ parent() }}
{% set tabContent %}
  {% set head %}
    {{ table.column("Predmet", "sortable-text") }}
    {{ table.column("Čas", "sortable-text") }}
    {{ table.column("Dátum", "sortable-date-dmy") }}
    {{ table.column("Miestnosti", "sortable-text") }}
    {{ table.column("Hodnotiaci", "sortable-text") }}
    {{ table.column("Počet prihlásených študentov", "sortable-numeric") }}
    {{ table.column("Maximálny počet", "sortable-numeric") }}
    {{ table.column("Poznámka", "sortable-text") }}
    {{ table.column("Interval pre prihlasovanie",
                    "sortable-sortPrihlasovanieOdhlasovanie") }}
    {{ table.column("Interval pre odhlasovanie",
                    "sortable-sortPrihlasovanieOdhlasovanie") }}
    {{ table.column("Prihlás", "") }}
  {% endset %}

  {% macro riadok(row, prihlas, studium, zapisnyList, action) %}
    {% url link for {'action': action,
                     'studium': studium,
                     'list': zapisnyList,
                     'predmet': row.predmetIndex,
                     'termin': row.index} %}
    <td><a href="{{ link }}">{{ row.predmet }}</a></td>
    <td>{{ row.cas }}</td>
    <td>{{ row.dat }}</td>
    <td>{{ row.miestnosti }}</td>
    <td>{{ row.hodnotiaci }}</td>
    <td>{{ row.pocetPrihlasenych }}</td>
    <td>{{ row.maxPocet }}</td>
    <td>{{ row.poznamka }}</td>
    <td>{{ row.prihlasovanie }}</td>
    <td>{{ row.odhlasovanie }}</td>
    <td>{{ prihlas|raw }}</td>
  {% endmacro %}

  {% set body %}
    {% for row in terminy %}
      {{ table.row(none, (termin != none) and (row.index == termin)
                          and (row.index == termin) and (row.predmetIndex == predmet)) }}
        {% if row.mozeSaPrihlasit <= 0 %} {# moze sa prihlasit #}
          {% url form_action for {'action': 'studium.PrihlasNaSkusku',
                             'studium': studium,
                             'list': zapisnyList} %}
          {% set prihlas %}
            {# TODO(anty): update after those checks are moved to the model #}
            {% if row.mozeSaPrihlasit == constant("fajr\\controller\\studium\\MozePrihlasitNaTerminHelper::PRIHLASIT_MOZE_ZNAMKA") %}
              Už máš zapísané "{{ row.znamka }}"
            {% endif %}
            <form method='post' action='{{ form_action }}'>
              <div>
                <input type="hidden" name="prihlasPredmetIndex"
                       value="{{ row.predmetIndex }}" />
                <input type="hidden" name="prihlasTerminIndex"
                       value="{{ row.index }}" />
                <input type="hidden" name="hash" value="{{ row.hashNaPrihlasenie }}"/>
                <button name="submit" type="submit" class="tableButton positive">
                  <img src="images/third_party/silk/add.png" alt="" />Prihlás ma!
                </button>
              </div>
            </form>
          {% endset %}
        {% elseif row.mozeSaPrihlasit == constant("fajr\\controller\\studium\\MozePrihlasitNaTerminHelper::PRIHLASIT_NEMOZE_CAS") %}
          {% set prihlas="Nedá sa (mimo termínu prihlasovania)" %}
        {% elseif row.mozeSaPrihlasit == constant("fajr\\controller\\studium\\MozePrihlasitNaTerminHelper::PRIHLASIT_NEMOZE_POCET") %}
          {% set prihlas="Termín je plný" %}
        {% elseif row.mozeSaPrihlasit == constant("fajr\\controller\\studium\\MozePrihlasitNaTerminHelper::PRIHLASIT_NEMOZE_ZNAMKA") %}
          {% set prihlas %}Už máš zapísané "{{ row.znamka }}"{% endset %}
        {% else %}
          {% set prihlas="Nedá sa, dôvod neznámy" %}
        {% endif %}
        {{ _self.riadok(row, prihlas, studium, zapisnyList, action) }}
      {{ table.endrow() }}
    {% endfor %}
  {% endset %}

  {% set title %}
    <h2>Termíny, na ktoré sa môžem prihlásiť</h2>
  {% endset %}

  {% set tableHTML %}
  {{ decorators.table(none, head, body, none, terminy|length == 0) }}
  {% endset %}

  {{ decorators.collapsible(title, tableHTML, false) }}

  {# ---- zoznam prihlasenych --- #}
  {{ studiumMacros.zoznamPrihlasenych(prihlaseni) }}

{% endset %}

{{ studiumMacros.studiumTabs(tabContent, 'ZapisSkusok', studium, zapisnyList) }}
{% endblock %}
